/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2007 Miranda ICQ/IM project, 
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
aLONG with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#pragma once

#include "tinyxml/tinyxml.h"

namespace NExImport {

class CExImContactBase {
	BOOLEAN		compareUID(DWORD val, BYTE type);

protected:
	string		_strNick;		// utf8 encoded
	string		_strDisp;		// utf8 encoded
	string		_strGroup;		// utf8 encoded
	string		_strProto;
	string		_strUIDKey;
	DBVARIANT	_dbvUID;
	HANDLE		_hContact;
	BOOLEAN		_isNewContact;	// is this contact a new one?

	HANDLE		findHandle();

public:
	CExImContactBase();
	~CExImContactBase();

	__inline LPCSTR disp() const	{ return _strDisp[0] != 0 ? _strDisp.c_str() : NULL;		}
	__inline LPCSTR group() const	{ return _strGroup[0] != 0 ? _strGroup.c_str() : NULL;		}
	__inline LPCSTR nick() const	{ return _strNick[0] != 0 ? _strNick.c_str() : NULL;		}
	__inline LPCSTR proto() const	{ return _strProto[0] != 0 ? _strProto.c_str() : NULL;		}
	__inline LPCSTR uidk() const	{ return _strUIDKey[0] != 0 ? _strUIDKey.c_str() : NULL;	}
	__inline DBVARIANT& uid()		{ return _dbvUID;	}
	__inline HANDLE handle() const	{ return _hContact;	}
	
	__inline VOID	disp(LPCSTR val)		{ _strDisp =  val ? val : "";	}
	__inline VOID	group(LPCSTR val)		{ _strGroup =  val ? val : "";	}
	__inline VOID	nick(LPCSTR val)		{ _strNick =  val ? val : "";	}
	__inline VOID	proto(LPCSTR val)		{ _strProto =  val ? val : "";	}
	__inline VOID	uidk(LPCSTR val)		{ _strUIDKey =  val ? val : ""; }
	__inline VOID	uid(BYTE val)			{ _dbvUID.type = DBVT_BYTE; _dbvUID.bVal = val; }
	__inline VOID	uid(WORD val)			{ _dbvUID.type = DBVT_WORD; _dbvUID.wVal = val; }
	__inline VOID	uid(DWORD val)			{ _dbvUID.type = DBVT_DWORD; _dbvUID.dVal = val; }
	__inline VOID	uid(LPCSTR val)			{ _dbvUID.type = (_dbvUID.pszVal = mir_strdup(val)) ? DBVT_UTF8 : DBVT_DELETED; }


	BOOLEAN			isHandle(HANDLE hContact);
	BOOLEAN			isMeta() const;

	LPSTR			uid2String(BOOLEAN bPrependType);

	BOOLEAN			fromDB(HANDLE hContact);
	BOOLEAN			fromIni(string& row);

	HANDLE			toDB();
	VOID			toIni(FILE* file);

	BOOLEAN operator = (HANDLE hContact)	{ return fromDB(hContact);	}
};

typedef std::list<CExImContactBase> CExImContactBaseList;

} // namespace NExImport
